package com.lxs.ioperations;

import com.lxs.book.BookList;

import java.util.Scanner;
/**
 * 删除图书
 */
public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList){
        int i = 0;
        int number = bookList.getUseSize();
        Scanner scanner = new Scanner(System.in);
        System.out.println("删除图书......");
        System.out.print("请输入你要删除的书籍名称：");
        String name = scanner.nextLine();
        for (; i < number; i++) {
            if(name.equals(bookList.getBooks(i).getName())){
                System.out.println(bookList.getBooks(i));
                for (int j = i; j < bookList.getUseSize(); j++) {
                    bookList.setBooks(j, bookList.getBooks(j + 1));
                }
                System.out.println("删除成功！");
                bookList.setUseSize(number - 1);
                return ;
            }
        }
        if(i == bookList.getUseSize()){
            System.out.println("没有这本书！");
        }
    }
}